import axios from 'axios'
const request = axios.create({
  baseURL:"http://dida100.com:8888",
  timeout:5000
})
request.interceptors.request.use(config=>{
  if(sessionStorage.getItem("token")){
    config.headers["Authorization"] = "Bearer "+sessionStorage.getItem("token")
  }
  return config;
})

export default request

// 输入数据:
// var data = [{"createBy":"admin","createTime":"2023-02-15 09:07:48","updateBy":null,"updateTime":null,"remark":null,"boxId":23,"parentId":1,"boxLevel":null,"boxName":"嘎嘎","sort":1,"status":"0","delFlag":"0","child":null},{"createBy":"admin","createTime":"2023-02-15 09:08:05","updateBy":null,"updateTime":null,"remark":null,"boxId":24,"parentId":1,"boxLevel":null,"boxName":"嘎嘎2","sort":2,"status":"0","delFlag":"0","child":null},{"createBy":"admin","createTime":"2023-02-15 09:08:17","updateBy":null,"updateTime":null,"remark":null,"boxId":2,"parentId":1,"boxLevel":null,"boxName":"嘎嘎","sort":3,"status":"0","delFlag":"0","child":null},{"createBy":"admin","createTime":"2023-02-15 09:09:17","updateBy":null,"updateTime":null,"remark":null,"boxId":27,"parentId":2,"boxLevel":null,"boxName":"发生","sort":1,"status":"0","delFlag":"0","child":null},{"createBy":"admin","createTime":"2023-02-15 09:09:23","updateBy":null,"updateTime":null,"remark":null,"boxId":28,"parentId":2,"boxLevel":null,"boxName":"大萨达撒","sort":2,"status":"0","delFlag":"0","child":null}]
// function getTree(parent=1,list){
//   // 一般parentId会是0，你的数据里面parentId为1
//   // 把把你的数据一个有个boxId改为2，这样 27,28是这个2的子children
//   // 要返回的数组
//   var temp = [];
//   // 遍历数组
//   for(var i=0;i<list.length;i++){
//     // 如果parentId相同
//     if(list[i].parentId ===parent){
//       // 创建一个对象
//       var obj = {
//         label:list[i].boxName       
//       }
//       // 过滤出和当前parentId相同的向（肯定就不是当前的children）
//       var left = list.filter(item=>item.parentId!=parent);
//       // 递归获取
//       var re = getTree(list[i].boxId,left);
//       // 如果有children
//       if(re&&re.length){
//         // 添加children
//         obj.children = re;
//       }
     
//       temp.push(obj)     
//     }
//   }
//   return temp;

// }



//  输出数据：
//  [{
//   label: '一级 1',
//   children: [{
//     label: '二级 1-1',
//     children: [{
//       label: '三级 1-1-1'
//     }]
//   }]
// }  
// ]
// 写个js递归函数实现